import { Component, Injector} from '@angular/core';
import { BasePage } from './../../pages/basePage';
import { StorageService } from './../../providers/StorageService';
import { UserService } from './../../providers/UserService';

/**
 * Generated class for the ReadComponent component.
 *
 * See https://angular.io/api/core/Component for more info on Angular
 * Components.
 */
@Component({
  selector: 'read',
  templateUrl: 'read.html'
})
export class ReadComponent extends BasePage{

  text: string;

  /*读取用户信息*/
  userinfo={}
  /*存放总的用户消息列表*/
  userMsg=[]
  message_id=0;
  param={
    user_id:0
  }

  constructor(injector: Injector,  public stc: StorageService, public userService: UserService) {
    super(injector);
    console.log('Hello ReadComponent Component');
    this.text = 'Hello World';
    this.userinfo = this.stc.read('userinfo');
    console.log(this.userinfo['user_id']);
    this.getuserMsg();
  }
   /*获取已读消息列表*/
   async getuserMsg(){
    this.param.user_id=this.userinfo['user_id'];
    let result=await this.userService.getMsg(this.param);
    console.log(result)
    if (result) {
      for(let i=0;i<result.messages.length;i++){
        if(result.messages[i].is_read==1){
          this.userMsg.push(result.messages[i]);
        }
      }
      console.log(this.userMsg)
    }
    return false;
    
  }
}
